package com.autumn.common.api.constants;

import java.io.Serializable;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import com.autumn.common.api.domain.values.IntegerConstantItemValue;

/**
 * 简单数据类型常量
 * 
 * @author 杨昌国 2018-11-20 09:23:49
 */
public final class SimpleDataTypeConstant implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -126865785598698229L;

	/**
	 * 字符窜
	 */
	public static final int STRING = 1;

	/**
	 * 整数
	 */
	public static final int INTEGER = 2;

	/**
	 * 浮点数
	 */
	public static final int DOUBLE = 3;

	/**
	 * 金额类型
	 */
	public static final int DECIMAL = 4;

	/**
	 * 日期类型
	 */
	public static final int DATE = 5;

	/**
	 * 日期时间类型
	 */
	public static final int DATETIME = 6;

	/**
	 * 布尔类型
	 */
	public static final int BOOLEAN = 7;

	private static final Map<Integer, IntegerConstantItemValue> NAME_MAP = new HashMap<>();

	static {
		NAME_MAP.put(STRING, new IntegerConstantItemValue(STRING, "字符窜", ""));
		NAME_MAP.put(INTEGER, new IntegerConstantItemValue(INTEGER, "整数", ""));
		NAME_MAP.put(DOUBLE, new IntegerConstantItemValue(DOUBLE, "数字", ""));
		NAME_MAP.put(DECIMAL, new IntegerConstantItemValue(DECIMAL, "金额", ""));
		NAME_MAP.put(DATE, new IntegerConstantItemValue(DATE, "日期", ""));
		NAME_MAP.put(DATETIME, new IntegerConstantItemValue(DATETIME, "日期时间", ""));
		NAME_MAP.put(BOOLEAN, new IntegerConstantItemValue(BOOLEAN, "布尔(是/否)", ""));
	}

	/**
	 * 是否存在
	 * 
	 * @param value
	 *            值
	 * @return
	 */
	public static boolean exist(Integer value) {
		if (value == null) {
			return false;
		}
		return NAME_MAP.containsKey(value);
	}

	/**
	 * 获取名称
	 * 
	 * @param value
	 *            值
	 * @return
	 */
	public static String getName(Integer value) {
		IntegerConstantItemValue item = NAME_MAP.get(value);
		if (item == null) {
			return "";
		}
		return item.getName();
	}

	/**
	 * 项目集合
	 * 
	 * @return
	 */
	public static Collection<IntegerConstantItemValue> items() {
		return NAME_MAP.values();
	}
}
